package com.fdq.demo.controller;

import com.fdq.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: 83778
 * @date: 2023-11-14 20:48
 * @desc:
 */
@Controller
@RequestMapping("/api/student")
public class StudentController {

    @Autowired
    private StudentService studentService;


    @GetMapping("/home")
    public String home () {
        return "home";
    }

    @GetMapping("/exportExcel")
    @ResponseBody
    public void exportExcel(HttpServletRequest request , HttpServletResponse response) throws Exception {

        String token = request.getHeader("token");

        if (ObjectUtils.isEmpty(token)){

            throw new Exception("token为空....");
        }

        studentService.exportExcel(response,token);
    }

    @GetMapping("/exportExcel/{start}/{end}/{token}")
    public void exportWantExcel(HttpServletResponse response,
                                @PathVariable("start") Integer start,
                                @PathVariable("end") Integer end,
                                @PathVariable("token") String token){
        studentService.exportExcel(response,token);
    }

}
